package com.cskaoyan.controller;

import com.cskaoyan.bean.CskaoyanmallStorage;
import com.cskaoyan.service.CskaoyanmallStorageService;
import com.cskaoyan.vo.BaseRespVo;
import com.cskaoyan.vo.StorageVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class StorageController {

    @Autowired
    CskaoyanmallStorageService cskaoyanmallStorageService;

    //http://182.92.235.201:8083/admin/storage/list?page=1&limit=20&sort=add_time&order=desc
    //http://182.92.235.201:8083/admin/storage/list?page=1&limit=20&key=213&name=123&sort=add_time&order=desc
    @RequestMapping("admin/storage/list")
    public BaseRespVo list(Integer page, Integer limit, String name, String key, String sort, String order) {
    StorageVo storageVo = cskaoyanmallStorageService.query(page, limit,name,key,sort, order);
        return BaseRespVo.ok(storageVo);
    }


    //http://localhost:8083/admin/storage/delete
    @RequestMapping("admin/storage/delete")
    public BaseRespVo delete(@RequestBody CskaoyanmallStorage cskaoyanmallStorage) {
        int delete = cskaoyanmallStorageService.delete(cskaoyanmallStorage);
        if ( delete ==0 ){
            return BaseRespVo.ok();
        }else{
            return BaseRespVo.erro(662,"删除失败");
        }

    }
    ///admin/storage/update
    @RequestMapping("admin/storage/update")
    public BaseRespVo update(@RequestBody CskaoyanmallStorage cskaoyanmallAd) {
        int i = cskaoyanmallStorageService.updateByPrimaryKey(cskaoyanmallAd);
        if ( i ==1 ){
            return BaseRespVo.ok("更新成功");
        }else{
            return BaseRespVo.erro(662,"更新失败");
        }
    }

}
